<%@ page contentType="text/html;charset=utf-8" language="java"%>
<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>
<%@ taglib uri='http://java.sun.com/jsp/jstl/functions' prefix='fn'%>
<c:set var="path" value="${pageContext.request.contextPath}"/>
<c:set var="loginUserName" value="${sessionScope.loginDetail.name}"/>
<c:set var="loginDetail" value="${sessionScope.loginDetail}"/>
<c:set var="unReadCount" value="${sessionScope.unReadCount}"/>
<c:set var="loginUserType" value="${sessionScope.loginUser.userType}"/>
<script src="js/jquery-1.11.1.min.js" type="text/javascript"></script>
<script src="js/jquery.cookie.js" type="text/javascript"></script>
<script src="js/jquery.validate.js" type="text/javascript"></script>
<script src="js/jquery.metadata.js" type="text/javascript"></script>

<script >

var loginUserId = "${sessionScope.loginUser.userId}";
//ar loginUserName = "${sessionScope.loginUser.userName}";
var loginUserType = "${sessionScope.loginUser.userType}";
var loginUserPhoto = "${sessionScope.loginDetail.photo}";
var loginUserDetailId = "${sessionScope.loginDetail.id}";
var showWanShan = "${sessionScope.showWanShan}";
var unReadCount = "${sessionScope.unReadCount}";
var imgDomain = "http://7xi54c.com1.z0.glb.clouddn.com/";
var chars = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
$(function(){
	$.ajaxSetup({  
	    beforeSend:function(){
	    	return checkLogin();
	    }
	  
	});
});

function checkLogin(){
	if(loginUserId==null||loginUserId=="undefine"||loginUserId==""){
	var strUrl=window.location.href;
	var arrUrl=strUrl.split("/");
	var strPage=arrUrl[arrUrl.length-1];
	if(strPage.indexOf("test.jsp")>=0||strPage.indexOf("lxinfo.jsp")>=0||strPage.indexOf("dyinfo.jsp")>=0||strPage.indexOf("lxsinfo.jsp")>=0||strPage.indexOf("login.jsp")>=0||strPage.indexOf("join.jsp")>=0||strPage.indexOf("index.jsp")>=0||strPage.indexOf("lxslist.jsp")>=0||strPage.indexOf("dylist.jsp")>=0) {
		return true;
	}else{
		window.location.href='${path}/login.jsp';
		return false;
	}
	 
} 
};

function generateMixed(n) {
    var res = "";
    for(var i = 0; i < n ; i ++) {
        var id = Math.ceil(Math.random()*35);
        res += chars[id];
    }
    return res;
}
function request(paras){ 
    var url = location.href; 
    var paraString = url.substring(url.indexOf("?")+1,url.length).split("&"); 
    var paraObj = {} 
    for (i=0; j=paraString[i]; i++){ 
        paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length); 
    } 

    var returnValue = paraObj[paras.toLowerCase()]; 
    if(typeof(returnValue)=="undefined"){ 
        return ""; 
    }else{ 
        return returnValue; 
    } 
}
function formatLxsStatus(applyCount,guidestatus,commentstatus,startTimeCompare,teamId){
	var pingjiastr="<a class=\"no3\">正在进行</a>";
	
	if(guidestatus==0) {
		if(applyCount>0) {
			 pingjiastr="<a href=\"lxslogin_3_daoyou.jsp?teamId="+teamId+"\" class=\"no1\">有"+applyCount+"个导游申请</a>";
		}else{
			if(startTimeCompare==0){
				var pingjiastr="<a class=\"no2\">已过期</a>";
			}
		}
	}else{
		if(startTimeCompare==0) {
			if(commentstatus==0){
				 pingjiastr="<a href=\"lxslogin_4_pingjia.jsp?teamId="+teamId+"\" class=\"no1\">已发团</a>";
			}else if(commentstatus==1){
				 pingjiastr="<a href=\"lxslogin_4_pingjia.jsp?teamId="+teamId+"\" class=\"no1\">对方已评价</a>";
			}else if(commentstatus==2){
				 pingjiastr="<a href=\"lxslogin_4_pingjia_readonly.jsp?teamId="+teamId+"\" class=\"no1\">已评价</a>";
			}else if(commentstatus==3){
				 pingjiastr="<a href=\"lxslogin_4_pingjia_readonly.jsp?teamId="+teamId+"\" class=\"no2\">双方已互评</a>";
			}
		}else if(startTimeCompare==1) {
			var showStr= "<a href=\"javascript:getGuideIdByTeamId("+teamId+")\" class=\"no1\">【查看导游详情】</a>";
			 pingjiastr="<a href=\"lxslogin_3_daoyou.jsp?teamId="+teamId+"\" class=\"no4\">已确认"+showStr+"</a>";

		}
		
	}
	return pingjiastr;
}

function formatGuideStatus(userType,applyCount,guidestatus,commentstatus,status,startTimeCompare,teamId,travelorgId){
	var pingjiastr="";
	var showStr= "<a href=\"lxsinfo.jsp?travelorgId="+travelorgId+"\" class=\"no1\">【查看发团方详情】</a>";
	if(userType==1){
		showStr= "<a href=\"grinfo.jsp?personalId="+travelorgId+"\" class=\"no1\">【查看发团方详情】</a>";
	}
	if(guidestatus==0) {
		pingjiastr="<a class=\"no4\">已申请"+showStr+"</a>";
	}else{
		if(startTimeCompare==0) {
			if(commentstatus==0){
				 pingjiastr="<a href=\"dylogin_2_pingjia.jsp?teamId="+teamId+"&travelorgId="+travelorgId+"\" class=\"no1\">已发团</a>";
			}else if(commentstatus==1){
				 pingjiastr="<a href=\"dylogin_2_pingjia_readonly.jsp?teamId="+teamId+"&travelorgId="+travelorgId+"\" class=\"no1\">已评价</a>";
			}else if(commentstatus==2){
				 pingjiastr="<a href=\"dylogin_2_pingjia.jsp?teamId="+teamId+"&travelorgId="+travelorgId+"\" class=\"no1\">对方已评价</a>";
			}else if(commentstatus==3){
				 pingjiastr="<a href=\"dylogin_2_pingjia_readonly.jsp?teamId="+teamId+"&travelorgId="+travelorgId+"\" class=\"no2\">双方已互评</a>";
			}
		}else if(startTimeCompare==1) {//此处跳转需要改动
			if(status==2){
				var showStrGuide= "<a href=\"javascript:getGuideIdByTeamId("+teamId+")\" class=\"no5\">【查看导游详情】</a>";
				pingjiastr="<a href=\"javascript:void(0);\" class=\"no4\">很遗憾"+showStrGuide+""+showStr+"</a>";
			}else{
				pingjiastr="<a href=\"javascript:void(0);\" class=\"no4\">已确认"+showStr+"</a>";
			}
	
		}
	}
	return pingjiastr;
}
function logout(){
	var objp={};
	$.ajax({
		  url: '${path}/core/logout',
		  type: 'POST',
		  timeout: 30000,
		  cache : false,
	      data :objp,
	      async: false,
	      dataType:"json",      
          contentType:"application/json",   
	     // contentType: "application/json; charset=utf-8",
		  success:function(msg){
			  //alert(msg.totalCount)
			  window.location.href='${path}/login.jsp';
		  },
		   failure:function(msg){
			  // alert(eval('('+msg.responseText+')').error_text);
		   		
		   },
		   error:function(msg){
			  // alert(eval('('+msg.responseText+')').error_text); 
		   }
	});
}

function refreshWanShan(){
	var objp={};
	$.ajax({
		  url: '${path}/core/refreshWanShan',
		  type: 'POST',
		  timeout: 30000,
		  cache : false,
	      data :objp,
	      async: false,
	      dataType:"json",      
          contentType:"application/json",   
	     // contentType: "application/json; charset=utf-8",
		  success:function(msg){
			  //alert(msg.totalCount)
			 // window.location.href='${path}/login.jsp';
		  },
		   failure:function(msg){
			  // alert(eval('('+msg.responseText+')').error_text);
		   		
		   },
		   error:function(msg){
			  // alert(eval('('+msg.responseText+')').error_text); 
		   }
	});
}
function getGuideIdByTeamId(teamId){
	var guideId =-1;
	var objp= {};
	   $.ajax({
			  url: '${path}/core/getGuideByConfirm?teamId='+teamId,
			  type: 'POST',
			  timeout: 30000,
			  cache : false,
		      data :objp,
		      async: false,
		      dataType:"json",      
	          contentType:"application/json",   
		     // contentType: "application/json; charset=utf-8",
			  success:function(msg){
				  var guideData = msg.guide;
				  window.location.href='dyinfo.jsp?guideId='+guideData.id;
			  },
			   failure:function(msg){
				   //alert(eval('('+msg.responseText+')').error_text);
			   		
			   },
			   error:function(msg){
				  // alert(eval('('+msg.responseText+')').error_text); 
			   }
		});
	   return guideId;
}
</script>


